﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;
using InfoStrat.VE;
using InfoStrat.VE.NUI;
using OficinaTuristicaFE.Controls;
using Shared;
using DAL;
using OficinaTuristicaFE.RouteService;
using Microsoft.MapPoint.Rendering3D.Utility;
using Microsoft.MapPoint.Rendering3D;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using System.Xml;

namespace OficinaTuristicaFE
{
    /// <summary>
    /// Interaction logic for Map.xaml
    /// </summary>
    public partial class Map : SurfaceWindow
    {
        struct pushPinDeclaration
        {
            public string serviceType { get; set; }
            public string name { get; set; }
            public SurfaceVEPushPin pushPin { get; set; }
        }

        private ObservableCollection<ItineraryItem> _itineraries = new ObservableCollection<ItineraryItem>();
        public ObservableCollection<ItineraryItem> Itineraries                    
        {
            get { return _itineraries; }
        }

        public string emailAddress { get; set; }
        

        private ObservableCollection<string> _mailMessage=new ObservableCollection<string>();

       
        string routeDirection = "";
        string actualCulture;

        //Declaracio de es storyBoards
        Storyboard success;
        Storyboard failure;

        pushPinDeclaration selectedPushPin = new pushPinDeclaration(); //Destination selected

        private DataAccessLayer dal;
        
        pushPinDeclaration[] pushPinList = new pushPinDeclaration[100];
      
        List<BusinessCard> VCardList = new List<BusinessCard>();
      
        Item itemDetails = new Item();
       
        public List<Item> items { get; set; }

        Point YouAreHere = new Point();
                
        RouteService.Location location1 = new RouteService.Location();
        RouteService.Location location2 = new RouteService.Location();
        VELatLong bestView = new VELatLong();
        string key = "Aue4QbNvlkRcc5C60YnQWNMNvEZSSTC1mkv4jPD2kX49Jiw_5huBc_bTiYbaAAHx";

        /// <summary>
        /// Default constructor.
        /// </summary>
        public Map()
        {                      

            InitializeComponent();
                       

            // Add handlers for Application activation events
            AddActivationHandlers();

            location1.Latitude = OficinaTuristicaFE.Properties.Settings.Default.Latitud;
            location1.Longitude = OficinaTuristicaFE.Properties.Settings.Default.Longitud;

            YouAreHerepP.Latitude = OficinaTuristicaFE.Properties.Settings.Default.Latitud;
            YouAreHerepP.Longitude = OficinaTuristicaFE.Properties.Settings.Default.Longitud;

            //Oficina Turistica Son Servera
            YouAreHere.X = location1.Latitude;
            YouAreHere.Y = location1.Longitude;

            testlistbox.ItemsSource = _itineraries;
            returnCulture(); //Asignar el idioma

            ResourceDictionary rd = new ResourceDictionary();
            rd.Source = App.Language;
            this.Resources.MergedDictionaries.Add(rd);
        }

        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            dal = new DataAccessLayer();

            //Inicialitzar animacio i aturar
            success = (Storyboard)this.Resources["CheckAnimatio"];
            failure = (Storyboard)this.Resources["CrossAnimation"];

            System.Net.WebClient wc = new System.Net.WebClient();
            wc.OpenReadCompleted += new System.Net.OpenReadCompletedEventHandler(wc_OpenReadCompleted);
            wc.OpenReadAsync(new Uri("http://go.microsoft.com/fwlink/?LinkID=98774"));

        }

        void wc_OpenReadCompleted(object sender, System.Net.OpenReadCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                Microsoft.Surface.UserNotifications.RequestNotification((string)Resources["21"], (string)Resources["22"]);
            }
        }

        /// <summary>
        /// Occurs when the window is about to close. 
        /// </summary>
        /// <param name="e"></param>
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            // Remove handlers for Application activation events
            RemoveActivationHandlers();
        }

        /// <summary>
        /// Adds handlers for Application activation events.
        /// </summary>
        private void AddActivationHandlers()
        {
            // Subscribe to surface application activation events
            ApplicationLauncher.ApplicationActivated += OnApplicationActivated;
            ApplicationLauncher.ApplicationPreviewed += OnApplicationPreviewed;
            ApplicationLauncher.ApplicationDeactivated += OnApplicationDeactivated;
        }

        /// <summary>
        /// Removes handlers for Application activation events.
        /// </summary>
        private void RemoveActivationHandlers()
        {
            // Unsubscribe from surface application activation events
            ApplicationLauncher.ApplicationActivated -= OnApplicationActivated;
            ApplicationLauncher.ApplicationPreviewed -= OnApplicationPreviewed;
            ApplicationLauncher.ApplicationDeactivated -= OnApplicationDeactivated;
        }

        /// <summary>
        /// This is called when application has been activated.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnApplicationActivated(object sender, EventArgs e)
        {
            //TODO: enable audio, animations here

        }

        /// <summary>
        /// This is called when application is in preview mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnApplicationPreviewed(object sender, EventArgs e)
        {
            //TODO: Disable audio here if it is enabled

            //TODO: optionally enable animations here
        }

        /// <summary>
        ///  This is called when application has been deactivated.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnApplicationDeactivated(object sender, EventArgs e)
        {
            //TODO: disable audio, animations here
        }
        private void SurfacePushPin_Click(object sender, VEPushPinClickedEventArgs e)
        {
           // Point scatterOffset = new Point();
            Point scatterCenter = new Point();

            SurfaceVEPushPin pin = sender as SurfaceVEPushPin;
            int i = 0;
            if (pin != null)
            {
                while (pushPinList[i].pushPin != null)
                {
                    if (pin.Latitude == pushPinList[i].pushPin.Latitude || pin.Longitude == pushPinList[i].pushPin.Longitude)
                    {
                        selectedPushPin.pushPin = pushPinList[i].pushPin;
                        selectedPushPin.name = pushPinList[i].name;
                        selectedPushPin.serviceType = pushPinList[i].serviceType;
                        break;
                    }
                    i++;
                }
            }
            MapVE.FlyTo(pin.LatLong, -90, 0, 3000, null);

            if (selectedPushPin.pushPin != null)
            {
                itemDetails = dal.GetItemDetails(selectedPushPin.serviceType, selectedPushPin.name, App.LanguageItem);
                if (itemDetails != null)
                {
                    ScatterViewItem svi = new ScatterViewItem();  
                    BusinessCard VCard = new BusinessCard();
                    VCard.DataContext = itemDetails;
                   // VCard.Button_2.Content = "Get Route";
                    VCard.Image = ServiceList.ImageFromBuffer(itemDetails.Image);
                    if (selectedPushPin.serviceType != "Routes")
                    {
                        VCard.click += new RoutedEventHandler(ShowOnMap_Click);
                    }
                    else
                    {
                        VCard.click += new RoutedEventHandler(ViewRoute_click);
                    }
                    VCard.closeClick += new RoutedEventHandler(VCard_closeClick);
                    for (i = 0; i < VCardList.Count; i++)
                    {
                        //PAU: 
                        if (((Item)((BusinessCard)VCardList[i]).DataContext).CompanyName == ((Item)((BusinessCard)VCard).DataContext).CompanyName)
                        {
                            Type m;
                            foreach (ScatterViewItem item in ScatterMap.Items)
                            {
                                m = item.Content.GetType();
                                if (m.Name == "Viewbox")
                                {
                                    m = ((Viewbox)item.Content).Child.GetType();
                                    if (m.Name == "BusinessCard")
                                    {
                                        if (((Item)((BusinessCard)VCard).DataContext).CompanyName == ((BusinessCard)((Viewbox)item.Content).Child).Title.Content.ToString())
                                        {
                                            svi = item;
                                        }
                                    }
                                }
                            }
                            location2.Latitude = selectedPushPin.pushPin.Latitude;
                            location2.Longitude = selectedPushPin.pushPin.Longitude;
                            scatterCenter.X = e.PushPinScreenPosition.X;
                            scatterCenter.Y = e.PushPinScreenPosition.Y;
                            svi.Center = scatterCenter;
                            svi.Orientation = 0;
                            svi.IsActive = true;
                            return;
                        }
                    }
                    VCard.printClick += new RoutedEventHandler(VCard_printClick);
                    VCard.mailClick += new RoutedEventHandler(Mail_Click);
                    ControlTemplate routeTemplate= VCard.FindResource("GetRouteStyleTemplate") as ControlTemplate;
                    if (routeTemplate != null)
                    {
                        VCard.ShowOnMapButton.Template = routeTemplate;
                    //    VCard.ShowOnMapButton.SetValue(System.Windows.Controls.Control.TemplateProperty, routeTemplate);
                    }
                    VCard.StyleSuffix = selectedPushPin.serviceType;
                    VCardList.Add(VCard);
                    Viewbox myView = new Viewbox();
                    myView.Child = VCard;
                    svi.Content = myView;
                    svi.MaxHeight = 250;
                    svi.MinHeight = 100;
                    svi.MaxWidth = 450;
                    svi.MinWidth = 200;
                    svi.Height = 200;
                    svi.Width = 400;
                    //scatterOffset.X = svi.ActualWidth / 2;
                    
                    scatterCenter.X = e.PushPinScreenPosition.X;
                    scatterCenter.Y = e.PushPinScreenPosition.Y;
                    svi.Center = scatterCenter;
                    svi.Orientation = 0;  
                    ScatterMap.Items.Add(svi);
                    //PAU: Latitud y longitud para el caso que se quiera calcular la ruta
                    location2.Latitude = selectedPushPin.pushPin.Latitude;
                    location2.Longitude = selectedPushPin.pushPin.Longitude;
                }
            }
        }
        
        void VCard_printClick(object sender, RoutedEventArgs e)
        {
            try
            {
                ServiceList.PrintBusinessCard((BusinessCard)sender);
            }
            catch (Exception ex)
            {
                Microsoft.Surface.UserNotifications.RequestNotification((string)this.Resources["23"], (string)this.Resources["24"]);
            }
            itemDetails = (Item)((BusinessCard)sender).DataContext;           
        }
        private void map_MapLoaded(object sender, EventArgs e)
        {
            MapVE.LatLong = YouAreHere; //Ajuntament de Son Servera
            
            fillPushPintList(items);            
        }        
        
        private void ShowOnMap_Click(object sender, RoutedEventArgs e)
        {
            itemDetails = (Item)((BusinessCard)sender).DataContext;
            location2.Latitude = (double) itemDetails.Latitude;
            location2.Longitude = (double) itemDetails.Longitude;
            try
            {
                GetRoute(location1, location2);
            }
            catch (Exception ex)
            {
                Microsoft.Surface.UserNotifications.RequestNotification((string)this.Resources["19"], (string)this.Resources["20"]);
                return;
            }
            MapVE.FlyTo(bestView, -90, 0, bestView.Altitude, null);
        }
        private void ViewRoute_click(object sender, RoutedEventArgs e)
        {
            viewRoute(itemDetails.Route);
        }
        
        private void fillPushPintList(List<Item> itemList)
        {

            if (itemList != null)
            {
                for (int i = 0; i < itemList.Count(s => s != null); i++)
                {
                    pushPinList[i].pushPin = new SurfaceVEPushPin();
                    if (itemList[i].serviceType != null)
                    {
                        pushPinList[i].pushPin.PushPinBackground = (Brush)FindResource("PushPin" + itemList[i].serviceType);
                        
                    }
                    pushPinList[i].pushPin.Latitude = (double)itemList[i].Latitude;
                    pushPinList[i].pushPin.Longitude = (double)itemList[i].Longitude;
                    pushPinList[i].name = itemList[i].CompanyName;
                    pushPinList[i].serviceType = itemList[i].serviceType;
                    pushPinList[i].pushPin.Click += new EventHandler<VEPushPinClickedEventArgs>(SurfacePushPin_Click);
                    MapVE.Items.Add(pushPinList[i].pushPin);

                }
                if (App.FirstTime == 0)
                {                    
                    MapVE.FlyTo(pushPinList[0].pushPin.LatLong, -90, 0, 20000, null);
                    App.FirstTime = 1;
                }
                else
                {

                }
            }
            else
            {   
                MapVE.FlyTo(MapVE.VELatLong, -90, 0, 20000, null);
            }
        }
        public RouteResult GetRoute(RouteService.Location loc1, RouteService.Location loc2)
        {
            Itineraries.Clear();               

            RouteRequest routeRequest = new RouteRequest();
            MajorRoutesRequest mreq = new MajorRoutesRequest();

            // Set the credentials using a valid Bing Maps key
            routeRequest.Credentials = new RouteService.Credentials();
            routeRequest.Credentials.ApplicationId = key;

            Waypoint[] wps = new Waypoint[2];
            wps[0] = new Waypoint();
            wps[0].Location = new RouteService.Location();
            wps[0].Location.Latitude = loc1.Latitude;
            wps[0].Location.Longitude = loc1.Longitude;
            wps[1] = new Waypoint();
            wps[1].Location = new RouteService.Location();
            wps[1].Location.Latitude = loc2.Latitude;
            wps[1].Location.Longitude = loc2.Longitude;

            routeRequest.Waypoints = wps;
            routeRequest.Options = new RouteOptions();
            routeRequest.Options.Optimization = RouteOptimization.MinimizeDistance;
            routeRequest.Options.RoutePathType = RoutePathType.Points;
            routeRequest.Options.Mode = TravelMode.Driving;
            routeRequest.Culture = actualCulture;

            routeRequest.UserProfile = new RouteService.UserProfile();
            routeRequest.UserProfile.DistanceUnit = RouteService.DistanceUnit.Kilometer;

            // Make the calculate route request
            RouteServiceClient routeService = new RouteServiceClient("BasicHttpBinding_IRouteService");
            RouteResponse routeResponse = routeService.CalculateRoute(routeRequest);
                
            //  routeResponse.Result.Legs[0].Itinerary
            calculateBestView(routeResponse.Result.Legs[0]);
                
            PolyInfo polylineStyle = PolyInfo.DefaultPolyline;
            polylineStyle.LineWidth = 4;
            polylineStyle.AltitudeMode = AltitudeMode.FromDatum;

            //  StringBuilder latLongBuilder = new StringBuilder();
            List<LatLonAlt> lla = new List<LatLonAlt>();

            foreach (var point in routeResponse.Result.RoutePath.Points)
            {
                lla.Add(new LatLonAlt(point.Latitude * Math.PI / 180.0, point.Longitude * Math.PI / 180.0, 0));
            //      latLongBuilder.Append(point.Latitude + "-" + point.Longitude + "\n");
            }

            MapVE.GlobeControl.Host.Geometry.Clear();

            MapVE.GlobeControl.Host.Geometry.AddGeometry(new PolylineGeometry("route", Guid.NewGuid().ToString(),
                                                                                    null, lla.ToArray(),
                                                                                    PolylineGeometry.PolylineFormat.
                                                                                    Polyline2D, polylineStyle));

            foreach (var itineraryItem in routeResponse.Result.Legs[0].Itinerary)
            {
                Itineraries.Add(itineraryItem);
            }

            RouteDisplay.Visibility = Visibility.Visible;
            StringBuilder directions = new StringBuilder("");

            if (routeResponse.Result.Legs.Length > 0)
            {
                int instructionCount = 0;
                int legCount = 0;

                foreach (RouteLeg leg in routeResponse.Result.Legs)
                {
                    legCount++;
                    directions.Append(string.Format("Ruta #{0}\n", legCount));

                    foreach (ItineraryItem item in leg.Itinerary)
                    {
                        instructionCount++;
                        directions.Append(string.Format("{0}. {1}\n",
                            instructionCount, item.Text));
                    }
                }
                //Remove all Bing Maps tags around keywords.  
                //If you wanted to format the results, you could use the tags
                Regex regex = new Regex("<[/a-zA-Z:]*>",
                    RegexOptions.IgnoreCase | RegexOptions.Multiline);
                routeDirection = regex.Replace(directions.ToString(), string.Empty);

                //Add Destination to RouteDisplay but just once                    
                ToText.Text = " " + itemDetails.CompanyName;

                //  _mailMessage.Clear();
                //  results.Split('\n').ToList().ForEach((a) => _mailMessage.Add(a));
            }
            else
                routeDirection = "No Route found";

            if (routeResponse.Result != null)
            {
                return routeResponse.Result;
            }
            else
            {
                return null;
            }            
        }

        private void calculateBestView(RouteLeg itinerary)
        {
            double maxLat = -90;
            double minLat = 90;
            double maxLon = -180;
            double minLon = 180;

            for (int i = 0; i < itinerary.Itinerary.Length; i++)
            {
                if (itinerary.Itinerary[i].Location.Latitude > maxLat) maxLat = itinerary.Itinerary[i].Location.Latitude;
                if (itinerary.Itinerary[i].Location.Latitude < minLat) minLat = itinerary.Itinerary[i].Location.Latitude;
                if (itinerary.Itinerary[i].Location.Longitude > maxLon) maxLon = itinerary.Itinerary[i].Location.Longitude;
                if (itinerary.Itinerary[i].Location.Longitude < minLon) minLon = itinerary.Itinerary[i].Location.Longitude;
            }

            bestView.Latitude = (maxLat + minLat) / 2;
            bestView.Longitude = (maxLon + minLon) / 2;

            bestView.Altitude = itinerary.Summary.Distance * 1000;
          //  bestView.Altitude = itinerary
        }

        private void returnCulture()
        {
            switch (App.LanguageItem)
            {
                case 0:
                    actualCulture = "es-ES";
                    break;
                case 1:
                    actualCulture = "es-ES";
                    break;
                case 2:
                    actualCulture = "en-GB";
                    break;
                case 3:
                    actualCulture = "de-DE";
                    break;
            }
        }

        private void Mail_Click(object sender, RoutedEventArgs e)
        {
         //   string emailText = results.Replace("\n", Environment.NewLine);
            //System.Windows.Controls.TextBox InsertMail = new System.Windows.Controls.TextBox();
            ScatterEnterMail.Visibility = System.Windows.Visibility.Visible;
            MailSentAnimacioGrid.Visibility = System.Windows.Visibility.Hidden;
            if (sender.GetType().Name == "BusinessCard")
            {
                PrintMail((BusinessCard)sender);
              //  enterMailAddress.Focus();                
            }
            enterMailAddress.KeyDown += new System.Windows.Input.KeyEventHandler(enterMailAddress_KeyDown);
            enterMailAddress.Focus();
        }
        void enterMailAddress_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)        
        {
            if (e.Key.ToString() == "Return") 
            {
                SendMail();                
            }
        }

        private void PrintMail(BusinessCard businessCard)
        {
            routeDirection = businessCard.Title.Content + "\n" + ((Item)businessCard.DataContext).Description + "\n" + businessCard.Telefono.Text + "\n"
                + businessCard.Direccion.Text + "\n" + businessCard.Mail.Text;
        }

        private void Print_Click(object sender, RoutedEventArgs e)
        {
            itemDetails = (Item)((BusinessCard)sender).DataContext; 
            PrepareDocumentToPrint();
            Shared.PrintRoute print = new PrintRoute() {stringToPrint = routeDirection};
            try
            {
                print.DoPrint();
            }
            catch (Exception ex)
            {
                Microsoft.Surface.UserNotifications.RequestNotification((string)this.Resources["23"], (string)this.Resources["24"]);
            }
        }

        /// <summary>
        /// Insert Where and From in the route calculated
        /// and make it more readable
        /// </summary>
        private void PrepareDocumentToPrint()
        {
            routeDirection = "From: Oficina Turística Son Servera\nTo: " + selectedPushPin.name + "\n\n" + routeDirection + "\n\n" 
                                + "Ajuntament de Son Servera";               
        }


        private void SendMail()
        {
            //enviar el email
            //enterMailAddress.Text
            ScatterEnterMail.Visibility = System.Windows.Visibility.Hidden;

            //Amagar la animaccion del mail

            //MailSentAnimacioGrid.Visibility = System.Windows.Visibility.Hidden;


            Storyboard sendMailStory = (Storyboard)this.Resources["SendMailAnim"];
            sendMailStory.Stop();
            sendMailStory.Begin();
            
            success.Stop();
            failure.Stop();
            bool isSuccess = false;
         //   MailAnimcionGrid.Visibility = System.Windows.Visibility.Visible;

            //starts the mail send in a new thread
            System.Threading.ThreadPool.QueueUserWorkItem((o) =>
            {
                try
                {
                    if (itemDetails.Route == null)
                    {
                        Shared.Emailer.SendMessage((string)o, "test", routeDirection, itemDetails.Image, OficinaTuristicaFE.Properties.Settings.Default.useSSL);
                    }
                    else
                    {
                        Shared.Emailer.SendMessageWithAttachment((string)o, "Route Information", itemDetails.Route, "GPS Route", OficinaTuristicaFE.Properties.Settings.Default.useSSL);                       
                    }
                    isSuccess = true;
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                }
                finally
                {

                    //return to the windows thread using the dispatcher
                    App.Current.Dispatcher.BeginInvoke(new System.Threading.ThreadStart(() =>
                    {
                        sendMailStory.Stop();

                    }));
                }

                //return to the windows thread using the dispatcher
                App.Current.Dispatcher.BeginInvoke(new System.Threading.ThreadStart(() =>
                {
                    if (isSuccess)
                    {
                        failure.Stop();
                        success.Begin();
                    }
                    else
                    {
                        success.Stop();
                        failure.Begin();
                    }
                }));
            }, enterMailAddress.Text);
            enterMailAddress.Clear();
        }

        private void MailSendButton_Click(object sender, RoutedEventArgs e)
        {
            SendMail();            
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            MapVE.Dispose();
        }
        private void VCard_closeClick(object sender, RoutedEventArgs e)
        {
            BusinessCard vCardSelectedToClose = sender as BusinessCard;
            for (int i = 0; i < ScatterMap.Items.Count; i++)
            {
                Type m = ((ScatterViewItem)ScatterMap.Items[i]).Content.GetType();
                if (m.Name == "Viewbox")
                {
                    m = ((Viewbox)((ScatterViewItem)ScatterMap.Items[i]).Content).Child.GetType();
                    if (m.Name == "BusinessCard")
                        if (((Item)((BusinessCard)((Viewbox)((ScatterViewItem)ScatterMap.Items[i]).Content).Child).DataContext).CompanyName == ((Item)vCardSelectedToClose.DataContext).CompanyName)
                        {
                            ScatterMap.Items.Remove(ScatterMap.Items[i]);
                            VCardList.Remove(vCardSelectedToClose);
                            return;
                        }
                }
            }
        }

        private void CloseRouteDisplay_Click(object sender, RoutedEventArgs e)
        {
            RouteDisplay.Visibility = Visibility.Hidden;
        }

        private void CloseEnterMailAddress_Click(object sender, RoutedEventArgs e)
        {
            ScatterEnterMail.Visibility = System.Windows.Visibility.Hidden;
        }
       
        /// <summary>
        /// Visualizar la ruta predeterminada por un fichero gpx
        /// </summary>
        /// <param name="route"></param>
        private void viewRoute(string route)
        {
            PolyInfo polylineStyle = PolyInfo.DefaultPolyline;
            polylineStyle.LineWidth = 4;
            polylineStyle.AltitudeMode = AltitudeMode.FromDatum;

            RouteParse routeParse = new RouteParse();

            List<LatLonAlt> routeList = routeParse.LoadGPXTracks(route);
            MapVE.GlobeControl.Host.Geometry.AddGeometry(new PolylineGeometry("route", Guid.NewGuid().ToString(),
                                                                                       null, routeList.ToArray(),
                                                                                       PolylineGeometry.PolylineFormat.
                                                                                       Polyline2D, polylineStyle));

            ScatterEnterMail.Visibility = Visibility.Visible;
        }
    }
}